/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.prashant.sqlduniya.dbexplorer;

import java.util.List;

import org.openide.nodes.ChildFactory;
import org.openide.nodes.Node;
import org.openide.util.Lookup;
import org.prashant.sqlduniya.sqlmanager.DBConnectionManager;
import org.prashant.sqlduniya.sqlmanager.TableBean;

/**
 *
 * @author prashant
 */
public class CatalogChildFactory extends ChildFactory<TableBean> {

    private String catalog = null;
    private DBConnectionManager cm;
    
    public CatalogChildFactory(String catalog) {        
        this.catalog = catalog;
        this.cm = Lookup.getDefault().lookup(DBConnectionManager.class);
    }

    @Override
    protected boolean createKeys(List<TableBean> toPopulate) {
        System.out.println("CatalogChildFactory.createKeys = toPopulate" + toPopulate);
        List<String> tables = cm.loadTables(cm.getActiveConnection(), catalog);
        for (String table : tables) {
            TableBean aTable = new TableBean(table,catalog);
            toPopulate.add(aTable);
        }
        return true;
    }

    @Override
    protected Node createNodeForKey(TableBean key) {
        return new TableBeanNode(key);
    }
}
